﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

using Zarion_Quest.Base;
using Zarion_Quest.ShotTypes;
using Zarion_Quest.EnemyTypes;

namespace Zarion_Quest.LEVELS
{
    class Level2 : BaseLevel
    {
        Player player;
        SpaceEnemy enemy, enemy2;

        public Level2()
            : base()
        {
            player = new Player(Content.Load<Texture2D>("Content/LEVEL2/ShipTest"), 3, 1);
            enemy = new SpaceEnemy(Content.Load<Texture2D>("Content/LEVEL2/ShipTest"), 3, 1, 10);
            enemy2 = new SpaceEnemy(Content.Load<Texture2D>("Content/LEVEL2/ShipTest"), 3, 1, 10);

            player.Position = new Vector2(400, 500);
            enemy.Position = new Vector2(200, 100);
            enemy2.Position = new Vector2(600, 100);

            player.IsScreenBound = true;

            player.addNewAnimation("MoveSidewaysAnimation", 0, 3, 0.25f, false);
            player.addNewAnimation("StopedAnimation", 0, 1, 5f, false);
            player.addNewAnimation(Content.Load<Texture2D>("Content/LEVEL1/Walking"), 14, 1, "MegamanWalkingAnimation", 0, 14, 0.1f, true);
            player.PlayAnimation("StopedAnimation");

            enemy.addNewAnimation("StopedAnimation", 0, 1, 5f, false);
            enemy.PlayAnimation("StopedAnimation");

            enemy2.addNewAnimation("StopedAnimation", 0, 1, 5f, false);
            enemy2.PlayAnimation("StopedAnimation");
        }

        public override void Update(GameTime gameTime)
        {
            // F e H só para testar a alteração de sprite sheet...
            if (Game1.ks.IsKeyDown(Keys.H))
            {
                player.ObjectSpriteEffects = SpriteEffects.None;
                player.PlayAnimation("MegamanWalkingAnimation");
                player.moveOnX(3);
            }
            else if (Game1.ks.IsKeyDown(Keys.F))
            {
                player.ObjectSpriteEffects = SpriteEffects.FlipHorizontally;
                player.PlayAnimation("MegamanWalkingAnimation");
                player.moveOnX(-3);
            }
            else if (Game1.ks.IsKeyDown(Keys.D) || Game1.ks.IsKeyDown(Keys.Right))
            {
                player.ObjectSpriteEffects = SpriteEffects.None;
                player.PlayAnimation("MoveSidewaysAnimation");
                player.moveOnX(3);
            }
            else if (Game1.ks.IsKeyDown(Keys.A) || Game1.ks.IsKeyDown(Keys.Left))
            {
                player.ObjectSpriteEffects = SpriteEffects.FlipHorizontally;
                player.PlayAnimation("MoveSidewaysAnimation");
                player.moveOnX(-3);
            }
            else if (Game1.ks.IsKeyDown(Keys.W) || Game1.ks.IsKeyDown(Keys.Up))
            {
                player.PlayAnimation("StopedAnimation");
                player.moveOnY(-3);
            }
            else if (Game1.ks.IsKeyDown(Keys.S) || Game1.ks.IsKeyDown(Keys.Down))
            {
                player.PlayAnimation("StopedAnimation");
                player.moveOnY(3);
            }
            else
            {
                player.PlayAnimation("StopedAnimation");
            }
            if (Game1.isPressed(Keys.Space))
            {
                SeekerShot shot = new SeekerShot(Content.Load<Texture2D>("Content/Shots/DummyShot"), 1, 1, player.Position, EnemyManager.EnemyList, 2, 5, "Content/Shots/ShotFired", "Content/Shots/ShotHit", 5);
                shot.addNewAnimation("MoveSidewaysAnimation", 0, 1, 0.25f, false);
                shot.PlayAnimation("MoveSidewaysAnimation");
                player.shoot(shot);
            }
            player.Update(gameTime);
            EnemyManager.UpdateEnemies(gameTime);
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            player.Draw(spriteBatch);
            EnemyManager.DrawEnemies(spriteBatch);
        }
    }
}
